package models;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import siena.Generator;
import siena.Id;
import siena.Index;
import siena.Model;
import siena.NotNull;
import siena.Query;
import siena.core.Aggregated;


public class Event extends Model {

	@Id(Generator.AUTO_INCREMENT)
	private Long eventId;
	@NotNull
	private String name;
	@Index("user_index") @NotNull  
	private ArrayList<Long> admins;
	@Index("template_index") @NotNull
	private Template template;
	
	private ArrayList<Long>guests;
	//0 = attending, 1 = maybe, 2 = not coming 
	private ArrayList<Integer>guestAttendance;
	
	private ArrayList<Long> supplies;
	private ArrayList<Long>transportEntries;
	private ArrayList<Long>wallPosts;

	
	private Date created;
	private Date modified;
	
	private static int count;
	
	
	public Event(Template template, ArrayList<Long>admins, String name){
		super();
		this.template = template;
		this.admins = admins;
		this.name = name;
		created = new Date();
		modified = created;
		guests = new ArrayList<Long>();
		guestAttendance = new ArrayList<Integer>();
		
		if(template.tabs.contains(1)){
			this.supplies = new ArrayList<Long>();
		}
		if(template.tabs.contains(2)){
			this.transportEntries = new ArrayList<Long>();
		}
		if(template.tabs.contains(3)){
			this.wallPosts = new ArrayList<Long>();
		}
		count++;
	}
	
	public static Query<Event> all(){
		return Model.all(Event.class);
	}
	
	public static Event findById(Long id){
		return all().filter("eventId", id).get();
	}
	
	public static List<Event> findByUser(User user){
		return all().filter("user", user).fetch();
	}
	
	public static List<Event> findByName(String name){
		return all().filter("name", name).fetch();
	}

	public Long getEventId() {
		return eventId;
	}

	public void setEventId(Long eventId) {
		this.eventId = eventId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ArrayList<Long> getAdmins() {
		return admins;
	}

	public void setAdmins(ArrayList<Long> admins) {
		this.admins = admins;
	}

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}

	public ArrayList<Long> getGuests() {
		return guests;
	}

	public void setGuests(ArrayList<Long> guests) {
		this.guests = guests;
	}

	public ArrayList<Integer> getGuestAttendance() {
		return guestAttendance;
	}

	public void setGuestAttendance(ArrayList<Integer> guestAttendance) {
		this.guestAttendance = guestAttendance;
	}

	public ArrayList<Long> getSupplies() {
		return supplies;
	}

	public void setSupplies(ArrayList<Long> supplies) {
		this.supplies = supplies;
	}

	public ArrayList<Long> getTransportEntries() {
		return transportEntries;
	}

	public void setTransportEntries(ArrayList<Long> transportEntries) {
		this.transportEntries = transportEntries;
	}

	public ArrayList<Long> getWallPosts() {
		return wallPosts;
	}

	public void setWallPosts(ArrayList<Long> wallPosts) {
		this.wallPosts = wallPosts;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getModified() {
		return modified;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}

	public static int getCount() {
		return count;
	}

	public static void setCount(int count) {
		Event.count = count;
	}
	
	
	
	
}
